<template>
	<view class="box">
		<image class="backImg" :src="backImg" mode="widthFix">
			<view class="content">
				<u-icon name="arrow-leftward" color="#333333" size="52rpx" class="uicon" @click="back"></u-icon>
				<view class="img_position">
					<view class="myinput_flex">
						<input type="text" class="myinput" :value="inviteData.url" disabled />
						<!-- <image class="copy" @click="copy(inviteData.url)" src="../../../static/images/inviteCopy.png" mode="widthFix"></image> -->
					</view>
					<view class="redenve_title">
						<!-- 邀请码 -->
						{{ i18n.friend1 }}
					</view>
					<view class="redenve_code">{{ inviteData.invite_code }}</view>
					<uqrcode class="QR_code" ref="uQRCode" :text="QRcode" :size="100" />
					<!-- <image src="" mode="widthFix"></image> -->
					<view class="invite_btn" @click="make">
						<!-- 立即邀请 -->
						{{ i18n.friend2 }}
					</view>
				</view>
				<!-- 邀请规则 -->
				<view class="rule">{{ i18n.friend3 }}</view>
				<view class="rule_text" v-html="contentText"></view>
			</view>
		</image>
		
		<create-poster ref="poster" :avatar="avatar" :qrVal="QRcode" :inviteBg="backImg" :name="name" @finish="finish"></create-poster>
	</view>
</template>

<script>
export default {
	data() {
		return {
			inviteData: {},
			contentText: '',
			QRcode: '',
			backImg: '',
			
			avatar:'',
			name:'',
			posturl:''
		};
	},
	onShow() {
		this.recommend();
	},
	methods: {
		recommend() {
			this.$u.api
				.recommend()
				.then(res => {
					this.avatar = res.data.avatar
					this.name = res.data.nickname
					this.inviteData = res.data;
					this.QRcode = res.data.url;
					this.backImg = res.data.share.pic;
					console.log(this.QRcode);
					this.contentText = res.data.share.content;
				})
				.catch(err => {});
		},
		back() {
			uni.navigateBack({});
		},
		
		finish(data){
			this.posturl = data.url
			if(data.type==1)this.share()
		},
		make(){
			if(this.posturl){
				uni.previewImage({
					urls:[this.posturl]
				})
			}else{
				this.$refs.poster.create()
			}
		},
	}
};
</script>

<style lang="scss" scoped>
.box {
	width: 100%;
	min-height: 100vh;
	position: relative;
	background-color: #e91a00;
}

page {
	background-color: #e91a00;
}

.backImg {
	width: 100%;
	z-index: 999;
}

.content {
	position: absolute;
	min-height: 100vh;
	top: 0;
	width: 100%;
	background-color: #e91a00;

	.uicon {
		position: fixed;
		top: 80rpx;
		left: 34rpx;
		z-index: 9999999;
	}

	.img_position {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 522rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 999999;

		.myinput_flex {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 45rpx;
			margin: 60rpx 100rpx 0;
			border-radius: 24rpx;
			background-color: #ffedda;

			.myinput {
				width: 478rpx;
				// background-color: #FFEDDA;
				border-radius: 24rpx;
				text-align: left;
				text-indent: 32rpx;
				color: #ffa648;
				font-size: 24rpx;
			}

			.copy {
				width: 22rpx;
				margin-right: 18rpx;
			}
		}

		.redenve_title {
			color: #666666;
			font-size: 26rpx;
			margin-top: 40rpx;
		}

		.redenve_code {
			color: #f2111e;
			font-size: 38rpx;
			margin-top: 30rpx;
			font-weight: bold;
		}

		.QR_code {
			width: 216rpx;
			height: 216rpx;
			margin-top: 30rpx;
		}

		.invite_btn {
			height: 102rpx;
			background: linear-gradient(0deg, #fee15e, #ff780e);
			line-height: 102rpx;
			border-radius: 50rpx;
			box-shadow: -1rpx 7rpx 27rpx 0px rgba(190, 0, 14, 0.82);
			margin: 120rpx 100rpx 0;
			width: 70%;
			color: #fff;
			font-size: 36rpx;
		}
	}
}
.rule {
	background-image: url(../../../static/images/inviteDecorate.png);
	background-repeat: no-repeat;
	height: 74rpx;
	line-height: 74rpx;
	background-size: contain;
	margin: 1300rpx 200rpx 0;
	text-align: center;
	font-size: 42rpx;
	color: #fff8dd;
	font-weight: bold;
	font-style: italic;
}

.rule_text {
	margin: 60rpx 62rpx;
	color: #ffd1be;
	font-size: 26rpx;
	line-height: 38rpx;
}
</style>
